package com.lanjiu.lib.imclient.dto;

import android.text.TextUtils;

import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.pro.business.BusinessProtocolMessages;

/**
 * @description:
 * @author: Panwei
 * @date: 2020/1/4 15:25
 */
public class VersionDto extends Dto {

    // 设备类型(1:android；2:ios)
    private int deviceType;

    // 版本编号
    private int versionCode;

    // 版本名称
    private String versionName;

    // 是否强制(1:是；2:否)
    private int isConstraint;

    // 更新下载地址
    private String updatePath;

    // 更新简介
    private String updateDescribe;

    public VersionDto() {
        this.deviceType = 1;
    }

    public int getDeviceType() {
        return deviceType;
    }

    public int getVersionCode() {
        return versionCode;
    }

    public void setVersionCode(int versionCode) {
        this.versionCode = versionCode;
    }

    public String getVersionName() {
        return versionName;
    }

    public void setVersionName(String versionName) {
        this.versionName = versionName;
    }

    public int getIsConstraint() {
        return isConstraint;
    }

    public void setIsConstraint(int isConstraint) {
        this.isConstraint = isConstraint;
    }

    public String getUpdatePath() {
        return updatePath;
    }

    public void setUpdatePath(String updatePath) {
        this.updatePath = updatePath;
    }

    public String getUpdateDescribe() {
        return updateDescribe;
    }

    public void setUpdateDescribe(String updateDescribe) {
        this.updateDescribe = updateDescribe;
    }

    public VersionDto(BusinessProtocolMessages.CheckForUpdatesProtocol checkForUpdates) {
        this.deviceType = checkForUpdates.getDeviceType();
        this.versionCode = checkForUpdates.getVersionCode();
        this.versionName = checkForUpdates.getVersionName();
        this.isConstraint = checkForUpdates.getIsConstraint();
        this.updatePath = checkForUpdates.getUpdatePath();
        this.updateDescribe = checkForUpdates.getUpdateDescribe();
    }

    @Override
    public BusinessProtocolMessages.CheckForUpdatesProtocol toProtobuf() {
        BusinessProtocolMessages.CheckForUpdatesProtocol.Builder builder = BusinessProtocolMessages.CheckForUpdatesProtocol.newBuilder();
        builder.setDeviceType(deviceType);
        builder.setVersionCode(versionCode);
        if (!TextUtils.isEmpty(versionName))
            builder.setVersionName(versionName);
        builder.setIsConstraint(isConstraint);
        if (!TextUtils.isEmpty(updatePath))
            builder.setUpdatePath(updatePath);
        if (!TextUtils.isEmpty(updateDescribe))
            builder.setUpdateDescribe(updateDescribe);
        return builder.build();
    }
}
